<?php
include 'D:/dingjiangbbs/common/home.php';
//屏蔽notice错误
error_reporting(E_ALL ^ E_NOTICE);

/****************  全部版块  开始  **********************/
/************11111 站点信息版块 开始11111****************/

//定义变量部分
$web = 'phpxy';
$web_site    = WEB_SITE;
$views_home  = WEB_SITE.'views/home/';
$admin_home  = WEB_SITE.'admin/home/';
$admin_2 = WEB_SITE.'admin/admin/';

/****************站点信息 开始***********************/

//查询获取当前显示的数据
$table  = DB_TABLE_SITE;
$fields = 'stitle,url_name,URL,ICP';
$where  = "where sid=8";
$res_show = select($link,$table,$fields,$where);
//var_dump($res_show);

/****************站点信息 结束***********************/

/****************友情链接 开始***********************/

$table  = DB_TABLE_LINK;
$fields = 'displayorder,name,url,description,logo,lid';	
$where  = "order by displayorder desc";
$res_show2 = select($link,$table,$fields,$where);
//var_dump($res_show2);

/****************友情链接 结束***********************/
/************11111 站点信息版块 结束1111111****************/
/***#################################################**/
/***********222222 用户管理版块  开始2222222****************/
/****************  编辑用户 开始 *******************/

//定义变量部分
$web = 'phpxy';
$web_site    = WEB_SITE;
$views_home  = WEB_SITE.'views/home/';
$admin_home  = WEB_SITE.'admin/home/';
$admin_2     = WEB_SITE.'admin/admin/';

/**********数据库操作*****************/
//查询出user表的用户信息
$table  = DB_TABLE_USER;
$fields = 'grade,uid,username,regtime,usertype,allowlogin';
$where  = "where uisdel=0 order by regtime desc";
$res_user = select($link,$table,$fields,$where);
//var_dump($res_user);

//计算user表中用户的数量
$user_num = count($res_user);
//var_dump($user_num);

/******************暂时无用**************************/
/*
//循环打印 uid 
for ($i=0;$i<$user_num;$i++) {
	$uid = $res_user[$i]['uid'];
	$rows[] = $uid;
	//var_dump($uid);
	
	//计算 每个用户的 总rate
	$table  = DB_TABLE_DETAIL." where authorid=$uid order by authorid desc";
	$fields = 'rate';
	$res_sum  = sum($link,$table,$fields);
	var_dump($res_sum);
	$sum[] = $res_sum;
	//var_dump($sum);
}
//var_dump($rows);
$uid = implode(',',$rows);
//var_dump($uid);
//var_dump($sum);
//var_dump($sum[7]);

*/

/************** display 统一传值******************/
/*
//传值
$vars = compact('web','web_site','views_home','admin_home','admin_2','res_show','res_show2','res_user','user_num');
display('admin_cg.html',$vars);

/****************  编辑用户 结束*******************/

/****************  积分详情 链接 开始*******************/

//定义变量部分
$web = 'phpxy';
$web_site    = WEB_SITE;
$views_home  = WEB_SITE.'views/home/';
$admin_home  = WEB_SITE.'admin/home/';
$admin_2     = WEB_SITE.'admin/admin/';


//获取用户id
$id = $_GET['id'];
//var_dump($id);

//查询显示该用户原有信息
$table  = DB_TABLE_USER;
$fields = 'uid,sex,username,regtime,regip,email,lasttime,picture,autograph,birthday,place,realname';
$where  = "where uid=$id";
$res_detail = select($link,$table,$fields,$where);
//var_dump($res_detail);


/************** display 统一传值******************/
//传值
/*
$vars = compact('web','web_site','views_home','admin_home','admin_2','res_show','res_show2','res_user','user_num','res_detail');
display('admin_cg.html',$vars);
/****************  积分详情 链接  结束*******************/

/***********222222 用户管理版块  结束2222222****************/
/***#################################################**/
/***********33333  板块管理版块   开始333333***************/
/************管理版块 部分 开始********************/
//遍历parentid=0的版块
$table  = DB_TABLE_CG;
$fields = 'cid,classname,parentid,compere,orderby,description,cisdel';
$where  = "where cisdel<2 order by orderby desc";
$res_cg0 = select($link,$table,$fields,$where);
//var_dump($res_cg0);

/************管理版块 部分 结束********************/

/************添加版块 部分 开始********************/

$tablex  = DB_TABLE_CG;
$fieldsx = 'classname,cid,parentid';
$wherex  = "where parentid=0 order by orderby";
$res_x   = select($link,$tablex,$fieldsx,$wherex);
//var_dump($res_x);


/************添加版块 部分 结束********************/
/************** display 统一传值******************/

//传值
/*
$vars = compact('web','web_site','views_home','admin_home','admin_2','res_show','res_show2','res_user','user_num','res_detail','res_cg0','res_x');
display('admin_cg.html',$vars);
/***********33333  板块管理版块 结束 333333***************/
/***#################################################**/
/***********44444  帖子管理版块  开始 444444***************/
/**--------帖子管理 开始 --------------**/
//遍历出所有帖子
$table_y  = DB_TABLE_DETAIL;
$fields_y = 'id,title,classid,replycount,hits,authorid,addtime'; 
$where_y  = "where isdel=0 and first=1 order by addtime desc";
$res_y   = select($link,$table_y,$fields_y,$where_y);
//var_dump($res_y);
$num_y = count($res_y);
//var_dump($num_y);

//循环拿出authorid,cid,用以查找username,classname
for ($i=0;$i<$num_y;$i++) {

	$uid = $res_y[$i]['authorid'];
	//var_dump($uid);
	$table_u  = DB_TABLE_USER;
	$fields_u = 'username';
	$where_u  = "where uid=$uid";
	$res_u    = select($link,$table_u,$fields_u,$where_u);
	//var_dump($res_u);
	//$username[] = $res_u;
	//var_dump($username);

	$cid      = $res_y[$i]['classid'];
	//var_dump($cid);
	$table_c  = DB_TABLE_CG;
	$fields_c = 'cid,classname';
	$where_c  = "where cid=$cid";
	$res_c    = select($link,$table_c,$fields_c,$where_c);
	//var_dump($red_c);
}



/**--------帖子管理  结束--------------**/
/**--------帖子回收站 开始-----------------**/
//遍历出所有帖子
$table_r  = DB_TABLE_DETAIL;
$fields_r = 'id,title,classid,replycount,hits,authorid'; 
$where_r  = "where isdel=1 and first=1 order by addtime desc";
$res_r   = select($link,$table_r,$fields_r,$where_r);
//var_dump($res_r);
$num_r = count($res_r);
//var_dump($num_r);

//循环拿出authorid,cid,用以查找username,classname
for ($i=0;$i<$num_r;$i++) {

	$uid_r = $res_r[$i]['authorid'];
	//var_dump($uid_r);
	$table_ru  = DB_TABLE_USER;
	$fields_ru = 'username';
	$where_ru  = "where uid=$uid_r";
	$res_ru    = select($link,$table_ru,$fields_ru,$where_ru);
	//var_dump($res_ru);
	

	$cid_r      = $res_r[$i]['classid'];
	//var_dump($cid_r);
	$table_rc  = DB_TABLE_CG;
	$fields_rc = 'cid,classname';
	$where_rc  = "where cid=$cid_r";
	$res_rc    = select($link,$table_rc,$fields_rc,$where_rc);
	//var_dump($res_rc);
}

/**--------帖子回收站 结束-----------------**/
/**-------- 回帖管理 开始-----------------**/
//查询数据库中回复内容
$table_re  = DB_TABLE_DETAIL;
$fields_re = 'id,tid,authorid,content,classid';
$where_re  = "where isdel=0 and first=0 order by addtime desc";
$res_re    = select($link,$table_re,$fields_re,$where_re);
//var_dump($res_re);

//计算数据库内的回复内容总条数
$num_re = count($res_re);

for ($j=0;$j<$num_re;$j++) {

	//查询category表的classname
	$cid_rec    = $res_re[$j]['classid'];
	//var_dump($cid_rec);
	$table_rec  = DB_TABLE_CG;
	$fields_rec = 'classname';
	$where_rec  = "where cid=$cid_rec" ;
	$res_rec    = select($link,$table_rec,$fields_rec,$where_rec);
	//var_dump($res_rec);

	//查询user表的username
	$uid_reu    = $res_re[$j]['authorid'];
	//var_dump($uid_reu);
	$table_reu  = DB_TABLE_USER;
	$fields_reu = 'username';
	$where_reu  = "where uid=$uid_reu";
	$res_reu    = select($link,$table_reu,$fields_reu,$where_reu);
	//var_dump($res_reu);

}

/**-------- 回帖管理 结束-----------------**/
/***--------回帖回收站 开始 --------------------***/
//遍历出所有帖子
$table_rr  = DB_TABLE_DETAIL;
$fields_rr = 'id,tid,content,classid,authorid'; 
$where_rr  = "where isdel=1 and first=0 order by addtime desc";
$res_rr   = select($link,$table_rr,$fields_rr,$where_rr);
//var_dump($res_rr);
$num_rr = count($res_rr);
//var_dump($num_rr);

//循环拿出authorid,cid,用以查找username,classname
for ($k=0;$k<$num_rr;$k++) {

	$uid_rru = $res_rr[$k]['authorid'];
	//var_dump($uid_rru);
	$table_rru  = DB_TABLE_USER;
	$fields_rru = 'username';
	$where_rru  = "where uid=$uid_rru";
	$res_rru    = select($link,$table_rru,$fields_rru,$where_rru);
	//var_dump($res_rru);

	$cid_rrc      = $res_rr[$k]['classid'];
	//var_dump($cid_rrc);
	$table_rrc  = DB_TABLE_CG;
	$fields_rrc = 'cid,classname';
	$where_rrc  = "where cid=$cid_rrc";
	$res_rrc    = select($link,$table_rrc,$fields_rrc,$where_rrc);
	//var_dump($res_rrc);
}




/***--------回帖回收站 结束 --------------------***/

/***********44444  帖子管理版块  结束  444444***************/

/************** display 统一传值******************/
//传值

$vars = compact('web','web_site','views_home','admin_home','admin_2','res_show','res_show2','res_user','user_num','res_detail','res_cg0','res_x','res_y','num_y','res_u','res_c','res_r','num_r','res_ru','res_rc','res_re','num_re','res_rec','res_reu','num_rr','res_rr','res_rru','res_rrc');

display('admin_cg.html',$vars);

//mysqli_close($link);

/***##########     全部结束版块    ####################**/